import { expect } from '@jest/globals';
import fs from 'fs-extra';
import path from 'path';

import { buildHapsAndCheckFile } from '../../plugins/common-fun';
import {
  AbilityType,
  APIType,
  APIVersion,
  CaseLevel,
  IsEnable,
  LanguageType,
  ModuleTemplateType,
  RuntimeOSType,
  SDKType,
  SignType,
} from '../../plugins/project-builder/models/constants';
import { TestCaseBuilder } from '../../plugins/task-builder/task-case-builder';
import { ProjectBuildOption, TestCaseFun } from '../../plugins/task-builder/test-case';
import { TestTaskOption } from '../../plugins/task-builder/test-task-option';

const projectBuilderOption: ProjectBuildOption = {
  template: {
    sdk: SDKType.Single,
    runtimeOS: RuntimeOSType.HarmonyOS,
    apiVersion: APIVersion.API10,
    apiType: APIType.FA,
    language: LanguageType.ArkTs,
    abilityType: AbilityType.Application,
    entryTemplateType: ModuleTemplateType.EmptyAbility
  }
};

const taskConfig: TestTaskOption = {
  caseLevel: CaseLevel.L1,
  sign: SignType.NoSign,
  ohpmInstall: IsEnable.DisAble,
};

const testFun: TestCaseFun = async (project, taskConfig, record) => {
  await buildHapsAndCheckFile(project, taskConfig, record);

  // 判断输出文件
  const modulePath = project.getModule('entry').moduleRootPath();
  const outPutPath = path.resolve(modulePath, 'build');
  const existsOutPutPath = await fs.pathExists(outPutPath);
  expect(existsOutPutPath).toBe(true);
};


TestCaseBuilder.builder()
  .caseName('OPEN_LAB_ZOS_MENU_BUILD_FA_API10_ArkTs_001')
  .description('FA模型菜单栏Rebuild Project')
  .projectBuilderOption(projectBuilderOption)
  .taskConfig(taskConfig)
  .testFun(testFun)
  .load();
